#include "qdesignerplugin.h"

#include "qdesigner.h"

#include "../../lib/shared/widgetinterface.h"
#include "../../lib/shared/qwidgetfactory.h"
#include "../../include/qfindresult.h"

#include <qplugin.h>
#include <QDir>
#include <QApplication>
#include <QPluginLoader>


QDesignerWidget::QDesignerWidget(AbstractCore *core):
    m_core(core)
{
    m_widget=new QDesigner(core);
    m_text=tr("Project");
    m_icon=QIcon(":/images/mode_Design.png");
}

QString QDesignerWidget::text()
{
    return m_text;
}

QIcon   QDesignerWidget::icon()
{
    return m_icon;
}

int     QDesignerWidget::index()
{
    return 2;
}

QWidget* QDesignerWidget::widget()
{
    return m_widget;
}

bool    QDesignerWidget::enabled()
{
    return false;
}

QFindResult* QDesignerWidget::search(const QString& text,bool sensitive,bool whole)
{
    QFindResult *result=new QFindResult;

    return result;
}


void QDesignerPlugin::initPlugin(AbstractCore *core)
{

    QDir dir;
    dir.setPath(QApplication::applicationDirPath()+"/widgets/");
    QFileInfoList list=dir.entryInfoList(QDir::Files);
    for(int i=0;i<list.size();i++)
    {
        QPluginLoader load(list.at(i).filePath());

        if(load.load())
        {
            QWidgetPluginInterface *plugin=qobject_cast<QWidgetPluginInterface*>(load.instance());
            if(plugin!=NULL)
            {
                WidgetFactory::addPlugin(plugin);
            }
        }
    }

    QDesignerWidget *wid;
    wid=new QDesignerWidget(core);
    emit addObject(wid);
}

Q_EXPORT_PLUGIN2(QDesignerPlugin, QDesignerPlugin)
